#pragma once
#include <vector>
#include "ENet.h"

class TcpClient
{
public:
	TcpClient();
	~TcpClient();

	bool Connect(const char* server, int port, const char* passwd);
	void Disconnect(bool async = false, bool cleanup = true);
	void CleanUp();

	void AbortConnect();

	void SendBuff(const void* buff, size_t len, int channel, DWORD flag = ENet::ENET_PACKET_FLAG_RELIABLE);
	void SendPacket(ENet::ENetPacket* packet, int channel);

	void ServerMessage(const Command* cmd, size_t len);
	void ReceivePacket(int channel, ENet::ENetPacket *packet);

	void KeepAlive();
	
	void Update(float elapsedTime);

private:
	void OnServerInfo(const Command* cmd, size_t len);

private:
	ENet::ENetHost* mClientHost;
	ENet::ENetPeer* mCurPeer;
	ENet::ENetPeer* mConnPeer;
	int mBandWidthLimit;
	int mClientNum;
	bool mAccept;
};
